package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.*;
import com.itlong.cloud.POJO.VO.property.*;
import com.itlong.cloud.equip.property.IDeviceCloudControllerServiceClient;
import com.itlong.cloud.property.service.IDeviceCloudControllerService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <desc>
 *      设备服务暴露接口实现类。
 * </desc>
 *
 * @createDate 2017/08/29
 */
@RestController
public class DeviceCloudControllerServiceResource implements IDeviceCloudControllerServiceClient {

    @Autowired
    IDeviceCloudControllerService iDeviceCloudControllerService;

    /**
     * <desc>
     *      判断sn存在性
     * <desc/>
     *
     * @param sn
     * @return
     * @author Chunjian.G
     * @createDate 2018-01-02
     */
    @Override
    @RequestMapping(path = "smartCommunity/interface/controller/checkSnExist",method = {RequestMethod.POST})
    public Integer checkSnIsExists(@RequestParam("sn") String sn) throws Exception {
        return iDeviceCloudControllerService.checkSnIsExists(sn);
    }

    /**
     * <desc>
     *      获取设备的状态
     * </desc>
     *
     * @param sn
     * @return
     * @author Jiaqi.X
     * @createDate 2019/03/25
     */
    @RequestMapping(path = "smartCommunity/interface/controller/getDeviceStatus",method = RequestMethod.POST)
    public Integer getDeviceStatus(@RequestParam("sn") String sn){
        return iDeviceCloudControllerService.getDeviceStatus(sn);
    }

    /**
     * <desc>
     *      云控制器登录
     * </desc>
     *
     * @param sn
     * @param encryptionAbility
     * @return
     * @author Jiaqi.X
     * @createDate 2019/03/25
     */
    @RequestMapping(path = "smartCommunity/interface/controller/login",method = RequestMethod.POST)
    public CloudControllerVO login(@RequestParam("sn") String sn,@RequestParam("encryptionAbility") String encryptionAbility) throws Exception {
        return iDeviceCloudControllerService.login(sn,encryptionAbility);
    }

    /**
     * <desc>
     *      分页查询云群控器列表
     * </desc>
     *
     * @param propertyDeviceCloudControllerGetDTO 云群控器查询DTO
     * @return 分页结果
     * @author wangzhi
     * @createDate 2019/03/26
     */
    @Override
    @PostMapping(path = "property/cloudController/getPage")
    public Page<PropertyDeviceCloudControllerGetVO> getPage(@RequestBody PropertyDeviceCloudControllerGetDTO propertyDeviceCloudControllerGetDTO) throws Exception {
        return iDeviceCloudControllerService.getPage(propertyDeviceCloudControllerGetDTO);
    }

    /**
     * <desc>
     *      通过token获取用户信息
     * </desc>
     *
     * @param token
     * @return
     * @author Qiang.S
     * @createDate 2019/03/27
     */
    @Override
    @PostMapping(path = "smartCommunity/interface/controller/retrieve")
    public CloudControllerVO retrieve(@RequestParam("token")String token) {
        return iDeviceCloudControllerService.retrieve(token);
    }

    /**
     * <desc>
     *      查询单个云群控器
     * </desc>
     *
     * @param propertyDeviceCloudControllerGetDTO 云群控器查询DTO
     * @return 单个云群控器VO
     * @author wangzhi
     * @createDate 2019/03/27
     */
    @Override
    @PostMapping(path = "property/cloudController/getOne")
    public PropertyDeviceCloudControllerGetVO getOne(@RequestBody PropertyDeviceCloudControllerGetDTO propertyDeviceCloudControllerGetDTO) throws Exception {
        return iDeviceCloudControllerService.getOne(propertyDeviceCloudControllerGetDTO);
    }

    /**
     * <desc>
     *      上报设备能力集
     * </desc>
     *
     * @param deviceUnique 设备唯一码
     * @param productKey 阿里云产品key
     * @param deviceProJs 设备属性
     * @author Qiang.S
     * @createDate 2019/03/28
     */
    @RequestMapping(path = "/smartCommunity/interface/controller/reportCapacitySet",method = RequestMethod.POST)
    @Override
    public void reportCapacitySet(@RequestParam("deviceUnique")String deviceUnique,
                                  @RequestParam("productKey")String productKey,
                                  @RequestParam("deviceProJs")String deviceProJs) throws Exception {
        iDeviceCloudControllerService.reportCapacitySet(deviceUnique, productKey, deviceProJs);
    }

    /**
     * <desc>
     *      一键启用禁用设备
     * </desc>
     *
     * @return 受影响行数
     * @author wangzhi
     * @createDate 2019/03/27
     */
    @Override
    @PostMapping(path = "property/cloudController/setStatus")
    public Integer setStatus(@RequestParam("projectId") String projectId, @RequestParam("deviceUnique") String deviceUnique, @RequestParam("status") Integer status) throws Exception{
        return iDeviceCloudControllerService.setStatus(projectId,deviceUnique,status);
    }

    /**
     * <desc>
     *      获取云群控器可绑定的云电梯设备列表信息
     * </desc>
     *
     * @return 电梯设备列表信息
     * @author wangzhi
     * @createDate 2019/03/27
     */
    @Override
    @PostMapping(path = "property/cloudController/getCloudElevatorList")
    public List<PropertyDeviceCloudControllerEleVO> getCloudElevatorList(@RequestBody PropertyDeviceCloudControllerGetDTO propertyDeviceCloudControllerGetDTO) throws Exception {
        return iDeviceCloudControllerService.getCloudElevatorList(propertyDeviceCloudControllerGetDTO);
    }

    /**
     * <desc>
     *      校验所选云电梯的楼层映射表
     * </desc>
     *
     * @return 0-楼层对应表不一致，1-楼层对应表一致
     * @author wangzhi
     * @createDate 2019/03/28
     */
    @Override
    @PostMapping(path = "property/cloudController/checkElevatorFloorConfig")
    public int checkElevatorFloorConfig(@RequestParam("deviceUniqueElevators") String deviceUniqueElevators) throws Exception {
        return iDeviceCloudControllerService.checkElevatorFloorConfig(deviceUniqueElevators);
    }

    /**
     * <desc>
     *      校验所选云电梯的公共楼层是否一致
     * </desc>
     *
     * @return 0-不一致，1-一致
     * @author Juguang.S
     * @createDate 2020/06/10
     */
    @Override
    @PostMapping(path = "property/cloudController/checkElevatorCommonFloorConfig")
    public int checkElevatorCommonFloorConfig(@RequestParam("deviceUniqueElevators") String deviceUniqueElevators) throws Exception {
        return iDeviceCloudControllerService.checkElevatorCommonFloorConfig(deviceUniqueElevators);
    }

    /**
     * <desc>
     *      同步楼层映射表
     * </desc>
     *
     * @return 0-失败，1-成功
     * @author wangzhi
     * @createDate 2019/03/28
     */
    @Override
    @PostMapping(path = "property/cloudController/resetElevatorFloorConfig")
    public Integer resetElevatorFloorConfig(@RequestBody PropertyDeviceCloudControllerSaveDTO propertyDeviceCloudControllerSaveDTO) throws Exception {
        return iDeviceCloudControllerService.resetElevatorFloorConfig(propertyDeviceCloudControllerSaveDTO);
    }

    /**
     * <desc>
     *      同步公共楼层
     * </desc>
     *
     * @return 0-失败，1-成功
     * @author Juguang.S
     * @createDate 2020/06/10
     */
    @Override
    @PostMapping(path = "property/cloudController/resetElevatorCommonFloorConfig")
    public Integer resetElevatorCommonFloorConfig(@RequestBody PropertyDeviceCloudControllerSaveDTO propertyDeviceCloudControllerSaveDTO) throws Exception {
        return iDeviceCloudControllerService.resetElevatorCommonFloorConfig(propertyDeviceCloudControllerSaveDTO);
    }

    /**
     * <desc>
     *      保存云群控器信息
     * </desc>
     *
     * @return 0-失败，1-成功
     * @author wangzhi
     * @createDate 2019/03/28
     */
    @Override
    @PostMapping(path = "property/cloudController/save")
    public Integer save(@RequestBody PropertyDeviceCloudControllerSaveDTO propertyDeviceCloudControllerSaveDTO) throws Exception {
        return iDeviceCloudControllerService.save(propertyDeviceCloudControllerSaveDTO);
    }

    /**
     * <desc>
     *      更新云电梯缓存iot信息
     * </desc>
     *
     * @param cloudControllerVO
     * @return
     * @author Qiang.S
     * @createDate 2019/03/28
     */
    @RequestMapping(path = "/smartCommunity/interface/controller/updateCloudClusterIotCacheInfo",method = RequestMethod.POST)
    @Override
    public CloudControllerVO updateCloudClusterIotCacheInfo(@RequestBody CloudControllerVO cloudControllerVO) throws Exception {
       return iDeviceCloudControllerService.updateCloudClusterIotCacheInfo(cloudControllerVO);
    }

    /**
     * <desc>
     *      修改云群控器信息
     * </desc>
     *
     * @return 0-失败，1-成功
     * @author wangzhi
     * @createDate 2019/03/28
     */
    @Override
    @PostMapping(path = "property/cloudController/update")
    public Integer update(@RequestBody PropertyDeviceCloudControllerSaveDTO propertyDeviceCloudControllerSaveDTO) throws Exception {
        return iDeviceCloudControllerService.update(propertyDeviceCloudControllerSaveDTO);
    }

    /**
     * <desc>
     *      校验云群控器和云电梯是否正在执行预约，0否，1是
     * </desc>
     *
     * @return 0否，1是
     * @author wangzhi
     * @createDate 2019/05/06
     */
    @Override
    @PostMapping(path = "property/cloudController/checkCloudCallStatus")
    public Integer checkCloudCallStatus(@RequestBody PropertyDeviceCloudControllerSaveDTO propertyDeviceCloudControllerSaveDTO) throws Exception {
        return iDeviceCloudControllerService.checkCloudCallStatus(propertyDeviceCloudControllerSaveDTO);
    }

    /**
     * <desc>
     *      获取群控器设备详情
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author Jiaqi.X
     * @createDate 2019/08/13
     */
    @Override
    @PostMapping(path = "property/cloudController/getControllerFloorInfo")
    public CloudControllerFloorInfoVO getControllerFloorInfo(@RequestParam("deviceUnique") String deviceUnique){
        return iDeviceCloudControllerService.getControllerFloorInfo(deviceUnique);
    }
}
